package com.ruoyi.common.tio;

import org.tio.core.ChannelContext;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Zhoyq &lt;feedback@zhoyq.com&gt;
 * @date 2019-06-24
 */
public class WsOnlineContext {
    private static Map<String, ChannelContext> map = new ConcurrentHashMap<>();

    public static void bindUser(String userId, ChannelContext channelContext) {
        map.put(userId, channelContext);
    }

    public static ChannelContext getChannelContextByUser(String userId){
        return map.get(userId);
    }


    /**
     * 用户下线，不推消息
     * @author: suntf
     * @date: 2023/5/20 上午8:13
     * @param userId
     * @return void
     */
    public static void unbindChannel(String userId) {
         map.remove(userId);
    }

    /***
     * @description: 获取ws中所有人员
     * @author zgt
     * @param
     * @date: 2023/5/12 10:03
     */
    public static Set<String> getWSRegisterUser(){
        // 获取所有的key
        return map.keySet();
    }
}
